package com.pms.controller;

import com.pms.dto.ParkingPageQueryDTO;
import com.pms.dto.ParkingSaveDTO;
import com.pms.dto.ParkingUpdateDTO;
import com.pms.result.PageResult;
import com.pms.result.Result;
import com.pms.service.ParkingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "停车位相关接口")
@RestController
@RequestMapping("/parking")
@Slf4j
public class ParkingController {

    @Autowired
    private ParkingService parkingService;

    @ApiOperation("新增停车位")
    @PostMapping("/save")
    public Result<String> save(@RequestBody ParkingSaveDTO parkingSaveDTO){
        log.info("新增停车位,{}",parkingSaveDTO);
        parkingService.save(parkingSaveDTO);
        return Result.success();
    }

    @ApiOperation("停车位分页查询")
    @GetMapping("/page")
    public Result<PageResult> page(ParkingPageQueryDTO parkingPageQueryDTO){
        log.info("停车位分页查询,{}",parkingPageQueryDTO);
        PageResult pageResult=parkingService.page(parkingPageQueryDTO);
        return Result.success(pageResult);
    }

    @ApiOperation("根据id批量删除")
    @DeleteMapping("/delete")
    public Result<String> deleteBatch(@RequestParam List<Integer> ids){
        log.info("根据id批量删除,{}",ids);
        parkingService.deleteBatch(ids);
        return Result.success();
    }

    @ApiOperation("修改停车位信息")
    @PutMapping("/update")
    public Result<String> update(@RequestBody ParkingUpdateDTO parkingUpdateDTO){
        log.info("修改停车位信息,{}",parkingUpdateDTO);
        parkingService.update(parkingUpdateDTO);
        return Result.success();
    }

}
